(function () {

    return {
        before: function () {

        },
        after: function () {
            var _this = this;
            var onLoadSuccess=function () {
                _this.$(".e-update-status").click(function () {
                    var _this1=this;
                    var id = $(this).attr("data-id");
                    var html= $(_this1).html();
                    var status=null;
                    if(html=="禁用"){
                        status=1;
                    }else if(html=="启用"){
                        status=0;
                    }
                    ajaxPost({
                        url: "sysRole/updateStatus",
                        data: {"id": id,"status":status},
                        success: function (data) {
                            var row=_this.$(".bootstrapTable").bootstrapTable("getRowByUniqueId",id);
                            row.status=data.data.status;
                            _this.$(".bootstrapTable").bootstrapTable("updateByUniqueId",{id:id,row:row});
                            if(data.data.status==0){
                                toastr.success("启用成功");
                            }else if(data.data.status==1){
                                toastr.success("禁用成功");
                            }
                            onLoadSuccess();
                        }
                    });
                });
            }
            bootstrapTable(_this.$(".bootstrapTable"), {
                    url: 'sysRole/findPage',
                    columns: [
                        {
                            field: 'selectItem',
                            checkbox: true,
                        },
                        {
                            field: 'name',
                            title: '角色名',
                            sortable: true
                        }, {
                            field: 'status',
                            title: '状态',
                            sortable: true,
                            formatter:function(value){
                                if(value==0){
                                    return "启用";
                                }else if(value==1){
                                    return "禁用"
                                }
                            }
                        },
                        {
                            field: 'createDate',
                            title: '创建时间',
                            sortable: true
                        }
                        , {
                            field: 'operate',
                            title: '操作',
                            formatter: function (value, row, index) {
                                var updateStatus="禁用";
                                if(row.status==1){
                                    updateStatus="启用";
                                }
                                return bootstrapTableBtn(value, row, index, row.id).
                                joinBtn("e-go sysRole_info", "详情","href='module/sysRole/info?id="+row.id+"'").
                                joinBtn("e-go sysRole_update", "修改","href='module/sysRole/update?id="+row.id+"'").
                                joinBtn("e-go sysRole_setSysPermission", "配置权限","href='module/sysRole/setSysPermission?sysRoleId="+row.id+"'").
                                joinBtn("e-update-status sysRole_updateStatus",updateStatus,'data-id="'+row.id+'"').
                                joinBtn("e-table-delete sysRole_delete", "删除",'url="sysRole/delete" data-id="'+row.id+'"').toString();
                            }
                        }
                    ],
                    onLoadSuccess: function () {
                        onLoadSuccess();
                    }
                }
            );
        }
    }
});